import { Transform } from "./Transform";
import { GameObject } from "./GameObject";
import { System } from "./System";


export class TransformSystem extends System {

    onFrame() {
        this.gameObjectOnUpdate(this.rootGameObject);
    }

    gameObjectOnUpdate(gameObject: GameObject) {
        for (const behaviour of gameObject.behaviours) {
            const isTransform = (behaviour as any).__proto__.constructor.name === 'Transform';
            if (isTransform) {
                (behaviour as Transform).updateMatrix();
            }
        }
        for (const child of gameObject.children) {
            this.gameObjectOnUpdate(child);
        }
    }
}
